package com.carsystem.utils;


import lombok.Data;

@Data
public class ResultEntity<T> {

    public static final int SUCCESS = 200;
    public static final int FAIL = 400;
    public static final int NO_LOGIN = 401;

    private int code;
    private String message;
    private T data;

    public ResultEntity() {
    }

    public ResultEntity(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResultEntity(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 返回成功
     *
     * @param code
     * @param data
     */
    public ResultEntity(int code, T data) {
        this.code = code;
        this.data = data;
        this.message = "success";
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     */
    public static <T> ResultEntity<T> success(T data) {
        return new ResultEntity<T>(SUCCESS, "操作成功", data);
    }

    /**
     * 成功返回结果
     */
    public static <T> ResultEntity<T> success() {
        return  new ResultEntity<T>(SUCCESS, "操作成功");
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     * @param  message 提示信息
     */
    public static <T> ResultEntity<T> success(T data, String message) {
        return new ResultEntity<T>(SUCCESS, message, data);
    }

    /**
     * 失败返回结果
     */
    public static <T> ResultEntity<T> failed(int errorCode) {
        return new ResultEntity<T>(errorCode, "操作失败", null);
    }

    /**
     * 失败返回结果
     */
    public static <T> ResultEntity<T> failed(String message) {
        return new ResultEntity<T>(FAIL, message, null);
    }


    /**
     * 失败返回结果
     * @param message 提示信息
     */
    public static <T> ResultEntity<T> failed(int code,String message) {
        return new ResultEntity<T>(code, message, null);
    }

    public static <T> ResultEntity<T> failed(T data,String message) {
        return new ResultEntity<T>(FAIL, message, data);
    }

    /**
     * 失败返回结果
     */
    public static <T> ResultEntity<T> failed() {
        return  failed(FAIL);
    }

    public static Object badParameter() {
        return failed(401, "参数不对");
    }

    public static <T> ResultEntity<T> unLogin() {
        return  failed(NO_LOGIN);
    }

}
